package com.ler.fast.controller;

import com.ler.fast.config.HttpResult;
import com.ler.fast.entity.FooBean;
import com.ler.fast.entity.UserAccount;
import com.ler.fast.mapper.UserMapper;
import com.ler.fast.util.InjectUtil;
import com.ler.fast.util.SpringBeanFactoryUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author lww
 * @since 2020-05-27
 */
@Api(value = "/user", description = "用户")
@RestController
@RequestMapping("/user")
public class UserAccountController {

    @Resource
    private UserMapper userMapper;

    @ApiOperation("查询一个")
    @GetMapping(value = "/create", name = "查询一个")
    public HttpResult create() {
        UserAccount account = InjectUtil.inject();
        return HttpResult.success(account);
    }

    @ApiOperation(value = "销毁类")
    @GetMapping(value = "/destroy", name = "销毁类")
    public HttpResult destroy() {
        InjectUtil.destroy();
        return HttpResult.success();
    }

    @ApiOperation(value = "查询一个")
    @GetMapping(value = "/one", name = "true")
    public HttpResult one() {
        UserAccount account = SpringBeanFactoryUtils.getApplicationContext().getBean(UserAccount.class);
        return HttpResult.success(account);
    }

    @Resource
    private FooBean fooBean;

    @GetMapping("/{message}")
    public String bar(@PathVariable String message) {
        return fooBean.echoMessage(message);
    }

    @ApiOperation(value = "获取注入对象")
    @GetMapping(value = "/u", name = "获取注入对象")
    public HttpResult u() {
        FooBean fooBean = SpringBeanFactoryUtils.getApplicationContext().getBean(FooBean.class);
        System.out.println("fooBean = " + fooBean);
        return HttpResult.success(fooBean);
    }

    @ApiOperation(value = "获取注入对象")
    @GetMapping(value = "/u1", name = "获取注入对象")
    public HttpResult u1() {
        System.out.println("userMapper = " + userMapper);
        return HttpResult.success(userMapper);
    }

}
